package com.ruoyi.web.controller.tzzl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.tzzl.domain.WzArticle;
import com.ruoyi.tzzl.domain.vo.QueryVo;
import com.ruoyi.tzzl.service.IWzArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 文章管理Controller
 * @author by caoyong
 * @date 2022/11/17
 **/
@RestController
@RequestMapping("/tzzl/article")
public class WzArticleController extends BaseController {

    @Autowired
    private IWzArticleService wzArticleService;

    /**
     * 查询文章管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WzArticle wzArticle)
    {
        startPage();
        List<WzArticle> list = wzArticleService.selectWzArticleList(wzArticle);
        return getDataTable(list);
    }

    /**
     * 添加文章
     * */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WzArticle wzArticle){
        wzArticle.setCreateTime(new Date());
        return AjaxResult.success(wzArticleService.save(wzArticle));
    }

    /**
     * 批量删除文章
     * */
    @PostMapping("/removeByIds")
    public AjaxResult removeByIds(@RequestBody QueryVo queryVo){
       return AjaxResult.success(wzArticleService.removeByIds(queryVo.getIds()));
    }

    /**
     *修改文章
     * */
    @PostMapping("update")
    public AjaxResult update(@RequestBody WzArticle wzArticle){
        return AjaxResult.success(wzArticleService.update(wzArticle));
    }

}
